// Copyright © 1993-94 Apple Computer, Inc. All rights reserved.

constant kAppName := '|Wrapper:PIEDTS|;

// ---- End Project Data ----


// ---- File Wrap It Up.t ----
paragraphApp :=
   {title: "Wrap It Up",
    viewBounds: {top: 0, left: 0, right: 240, bottom: 336},
    viewSetupFormScript:
      func()
      begin
      	constant kMaxWidth := 240;
      	constant kMaxHeight := 336;
      
      	local b := GetAppParams();
      
      	self.viewBounds := RelBounds(b.appAreaLeft, b.appAreaTop,
      											Min(b.appAreaWidth, kMaxWidth),
      											Min(b.appAreaHeight, kMaxHeight)
      										);
      end,
    _proto: protoApp,
    debug: "paragraphApp"
   };

_view000 := /* child of paragraphApp */
   {viewFlags: 33,
    viewFormat: 337,
    viewBounds: {left: 9, top: 25, right: 231, bottom: 159},
    viewclass: 77
   };

theParagraph := /* child of _view000 */
   {viewFlags: 6657,
    viewFormat: 337,
    viewFont: userFont12,
    viewBounds: {left: 9, top: 9, right: 215, bottom: 71},
    text: "Word",
    viewJustify: 0,
    viewclass: 81,
    debug: "theParagraph"
   };
// View theParagraph is declared to paragraphApp

// After Script for "theParagraph"
thisView := theParagraph;
begin
   thisView.viewFlags := BOR(thisView.viewFlags, vCalculateBounds);
   // Set the vCalculateBounds flag here, because it's not in the
   // viewFlags editor.

   thisView.viewLineSpacing := nil;
   // Make sure this slot is set here so it doesn't inherit
   // GetRoot() has a viewLineSpacing slot!
end





addAbove := /* child of paragraphApp */
   {text: "Add word above",
    buttonClickScript:
      func()
      begin
         SetValue(theParagraph, 'text, theParagraph.text && GetRandomWord(0, 20));
         SetValue(theParagraph, 'viewBounds, theParagraph.viewBounds);
      
         // the second SetValue is needed to tweak the clParagraphView into
         // updating an internal cache.  It's a workarond for a clParagraphView
         // bug.  The SetValue doesn't necessarily have to be for viewBounds.
      end,
    viewBounds: {left: 10, top: 170, right: 110, bottom: 182},
    _proto: protoTextButton,
    debug: "addAbove"
   };



addBelow := /* child of paragraphApp */
   {text: "Add word below",
    buttonClickScript:
      func()
      begin
         SetValue(anotherParagraph, 'text, anotherParagraph.text && GetRandomWord(0, 20));
      end,
    viewBounds: {left: 130, top: 170, right: 230, bottom: 182},
    _proto: protoTextButton,
    debug: "addBelow"
   };



anotherParagraph := /* child of paragraphApp */
   {viewFlags: 6657,
    viewFormat: 337,
    viewFont: userFont12,
    viewBounds: {left: 17, top: 193, right: 223, bottom: 209},
    text: "Word",
    viewJustify: 0,
    AdjustHeight:
      // This Function is based on Mike Engber's WrappedHeight utility
      // which calculates the height of wrapped text.  It's probably
      // better to just include that function in your application and
      // call it from here, but I didn't.  See the README for details.
      
      func()
      begin
         local width := viewBounds.right - viewBounds.left;
         local height := ComputeParagraphHeight(self,0,width);
       
         if height = 50 then begin
            local fontHeight := FontHeight(viewFont);
            local xNewLines  := ceiling(50/fontHeight);
            local xPara := {
                              viewFont: viewFont,
                              text: NStringCat(Stringer(Array(xNewLines,$\n)), text),
                            };
            height := ComputeParagraphHeight(xPara,0,width) - xNewLines*fontHeight;
         end;
      
         local newBounds := viewBounds;
         newBounds.bottom := newBounds.top + height;
         SetValue(self, 'viewBounds, newBounds);
      end;,
    viewChangedScript:
      func(slot, view)
      begin
         if slot = 'text and view = self then
            :AdjustHeight();
      end,
    viewclass: 81,
    debug: "anotherParagraph"
   };
// View anotherParagraph is declared to paragraphApp

// After Script for "anotherParagraph"
thisView := anotherParagraph;
thisView.viewLineSpacing := nil;

// Make sure this slot is set here so it doesn't inherit
// GetRoot() has a viewLineSpacing slot!







// ---- Beginning of section for non used Layout files ----

// End of output